package com.atguigu.lease.web.admin.custom.interceptors;

import com.atguigu.lease.common.exceptions.LeaseException;
import com.atguigu.lease.common.result.ResultCodeEnum;
import com.atguigu.lease.common.utils.JwtUtil;
import com.mysql.cj.util.StringUtils;
import io.netty.util.internal.StringUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

@Component
public class LoginIntercepotor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token=request.getHeader("access_token");
        System.out.println("token = " + token);
        if (StringUtils.isNullOrEmpty(token)){
            throw new LeaseException(ResultCodeEnum.ADMIN_LOGIN_AUTH);
        }
        JwtUtil.parseToken(token);
        return true;
    }
}
